 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.zdkj.common.core.exceltools.MultipartFileToFile;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;

import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.rca.entity.SwCkBackElectronicBillBocTmp;

import com.zdkj.subway.rca.service.SwCkBackElectronicBillBocTmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


/**
 * 中国银行电子账单临时表
 *
 * @author stw
 * @date 2020-09-27 11:22:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckbackelectronicbillboctmp" )
@Api(value = "swckbackelectronicbillboctmp", tags = "银行票据单管理-银行电子账单-中国银行电子账单临时表管理")
public class SwCkBackElectronicBillBocTmpController {

    @Autowired
    private final SwCkBackElectronicBillBocTmpService swCkBackElectronicBillBocTmpService;

    /**
     * 导入中国银行电子账单
     * @param file 上传的Excel文件
     * @return 成功或者失败
     * @throws Exception
     */
    @ApiOperation(value = "导入中国银行电子账单", notes = "导入中国银行电子账单")
    @SysLog("导入中国银行电子账单")
    @PostMapping({ "/saveBatch" })
    @PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_boc_tmp_import')")
    public R saveBatch(@RequestParam("file") final MultipartFile file) throws Exception {
        final File excelFile = MultipartFileToFile.multipartFileToFile(file);
        return R.ok((Object)this.swCkBackElectronicBillBocTmpService.saveBatchWithExcel(excelFile));
    }

    /**
     * 中国银行导入预处理查询
     * @return
     */
    @ApiOperation(value = "中国银行导入预处理查询", notes = "中国银行导入预处理查询")
    @GetMapping("/list" )
    @PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_boc_tmp_import')")
    public R getSwCkBackElectronicBillBocTmpList() {
        SwCkBackElectronicBillBocTmp swCkBackElectronicBillBocTmp = new SwCkBackElectronicBillBocTmp();
        final SwCkBackElectronicBillBocTmp obj =  ObjectUtils.getDefaultObj(SwCkBackElectronicBillBocTmp.class);
        swCkBackElectronicBillBocTmp.setCreatorId(obj.getCreatorId());
        return R.ok(swCkBackElectronicBillBocTmpService.list(Wrappers.query(swCkBackElectronicBillBocTmp)));
    }
    
    
    /**
     * 中国银行导入预处理确认
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "中国银行导入预处理确认", notes = "中国银行导入预处理确认")
    //@SysLog("中国银行导入预处理确认")
    @PostMapping({ "/saveBatchOk" })
    //@PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_boc_tmp_import')")
    public R saveBatchOk() throws Exception {
        final SwCkBackElectronicBillBocTmp obj =  ObjectUtils.getDefaultObj(SwCkBackElectronicBillBocTmp.class);
        this.swCkBackElectronicBillBocTmpService.saveBatchWithExcelOk(obj.getCreatorId());
        return R.ok(true);
    }
    
    
    /**
     * 中国银行导入预处理取消
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "中国银行导入预处理取消", notes = "中国银行导入预处理取消")
    @SysLog("中国银行导入预处理取消")
    @PostMapping({ "/saveBatchCancel" })
    @PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_boc_tmp_import')")
    public R saveBatchCancel() throws Exception {
        final SwCkBackElectronicBillBocTmp obj =  ObjectUtils.getDefaultObj(SwCkBackElectronicBillBocTmp.class);
        this.swCkBackElectronicBillBocTmpService.saveBatchWithExcelCancel(obj.getCreatorId());
        return R.ok(true);
    }

    /**
     * 导出模板
     * @param  response
     * @return
     * @throws
     */
    @ApiOperation(value = "导出模板", notes = "导出模板")
    @GetMapping("/exportTamplate")
    public void exportTamplate(HttpServletResponse response) {
        swCkBackElectronicBillBocTmpService.exportTamplates(response);
    }
}
